<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('申请标题')" prop="applyTitle">
            <el-input v-model="form.applyTitle" :placeholder="$t('申请标题')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('基金名称')" prop="fundId">
            <template>
              <router-link
                target="_blank"
                :to="{path:'/fund/fundBasehome',query:{id:form.fundId}}"
                class="link_a"
              >{{ form.fundName }} </router-link>
            </template>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('托管行')" prop="custodianBank">
            <el-input v-model="form.custodianBank" :placeholder="$t('托管行')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')">
            <el-input v-model="form.remark" type="textarea" maxlength="2000" :placeholder="$t('备注')" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="fund_wf_hosting" :business-id="autoBusinessId($route.query.id, form)" :btn-show="!otherBtnHide" />
    </el-form>
  </div>
</template>

<script>
    import { saveFundWfHosting, getFundWfHosting, getByWfNodeId } from '@/api/fund/wfForm/fundWfHosting'
    export default {
        data() {
            return {
                otherBtnHide: false,
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                custodianBank: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                applyTitle: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ]
                }
            }
        },
        created() {
          this.$bus.$emit('async_done')
        },
      mounted() {
      },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                  getFundWfHosting(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                  getByWfNodeId(data.wfNodeId).then(response => {
                    this.form = response.data
                    this.form.fileList = data.fileList
                    this.form.applyTitle = data.actTitle
                    this.loading = false
                  })
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,

                    fundName: undefined,

                    fundId: undefined,
                    custodianBank: undefined,
                    applyTitle: undefined,

                    remark: undefined,

                    createBy: undefined,

                    createTime: undefined,

                    updateBy: undefined,

                    updateTime: undefined,

                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            /** 提交按钮 */
            submitForm: function() {
              return new Promise((resolve, reject) => {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveFundWfHosting(this.form).then(response => {
                            if (response.code === 200) {
                                this.form.id = response.data.id
                                this.msgSuccess(this.$t('保存成功'))
                                this.loading = false
                                resolve(response.data.id)
                            } else {
                              this.msgError(response.msg)
                              this.loading = false
                              reject(response)
                            }
                        }).catch(() => {
                          this.loading = false
                        })
                    } else {
                       this.locationError(document)
                      reject()
                    }
                })
              })
           }
        }
    }
</script>
